package designpatterns.flyweight;

import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;
import java.util.Objects;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2/14/2022 9:14 PM
 */
@Slf4j
public class ShapeFactory {

    private static final HashMap<String, Circle> circleMap = new HashMap<>();

    public static Circle getCircle(String color) {
        Circle circle = circleMap.get(color);

        if (Objects.isNull(circle)) {
            circle = new Circle(color);
            circleMap.put(color, circle);
            log.info("创建一个 {} 颜色的Circle:", color);
        }
        return circle;
    }

}
